/**
 * 
 */
package model;

/**
 * @author yuqi
 *
 */
@SuppressWarnings("serial")
public class Date extends java.util.Date {

	/**
	 * 
	 */
	public Date() {
		super();
	}

	/**
	 * @param date
	 */
	public Date(long date) {
		super(date);
	}
	
	@SuppressWarnings("deprecation")
	public Date(String string) {
		int year = Integer.parseInt(string.substring(0, 4));
		int month = Integer.parseInt(string.substring(5, 7));
		int day = Integer.parseInt(string.substring(8,10));
		int hour = Integer.parseInt(string.substring(11,13));
		int min = Integer.parseInt(string.substring(14,16));
		int second = Integer.parseInt(string.substring(17, 19));
		
		this.setYear(year);
		this.setMonth(month);
		this.setDate(day);
		this.setHours(hour);
		this.setMinutes(min);
		this.setSeconds(second);
	}
	private String intToString(int i){
		String string =new Integer(i).toString();
		if(string.length()==1){
			return "0"+string;
		}else if(string.length()==0){
			return "00"+string;
		}else{
			return string;
		}
	}
	
	@SuppressWarnings("deprecation")
	@Override
	public String toString(){
		return ""+this.getYear()+"-"+intToString(this.getMonth())+"-"+intToString(this.getDay())+" "
		+intToString(this.getHours())+":"+intToString(this.getMinutes())+":"+intToString(this.getSeconds());
		
	}

}
